<template>
  <div>
    <Card>
      <Table
        :key="tableKey"
        :columns="spanColumns"
        :data-source="dataSource"
        :defaultExpandAllRows="true"
        :pagination="false"
        :scroll="{ y: 340 }"
      >
        <template #bodyCell="{ column, record }">
          <template v-if="column.dataIndex === 'action'">
            <a @click="setThreadTable(record)">分析</a>
            <Divider type="vertical" />
            <a @click="handleDetail(record)">查看详情</a>
          </template>
        </template>
      </Table>
    </Card>
  </div>
</template>
<script lang="ts" setup>
import { Table, Card, Divider } from 'ant-design-vue';
import { ref } from 'vue';
import { sampleTable } from '/@/api/maintenance-center/skywalking/profiling/profiling';
import { spanColumns } from '/@/views/maintenance-center/resource-monitor/skywalking/profiling/component/traceTable/data';
const dataSource = ref([]);
const tableKey = ref(0);

const segmentId = ref();

const getData = async () => {
  let res = await sampleTable(segmentId.value);
  tableKey.value++;
  dataSource.value = res;
};
const setTable = (sampleItem) => {
  segmentId.value = sampleItem.segmentId;
  getData();
};
const emit = defineEmits(['setThreadTable', 'setSpanDetail']);
const handleDetail = (record) => {
  emit('setSpanDetail', record);
};

const setThreadTable = (record) => {
  let threadParam = {
    segmentId: segmentId.value,
    timeRanges: [{ start: record.startTime, end: record.endTime }],
  };
  emit('setThreadTable', threadParam);
};
const clearTable = () => {
  dataSource.value = [];
};
defineExpose({ setTable, clearTable });
</script>
<style lang="less"></style>
